#include <cstdio>
#include <queue>
using namespace std;
const int MAXN = 1001;
int count[MAXN] = {0};
struct mouce{
    int weight;
    int rank;
}mouse[MAXN];
queue<int> que;
main()
{
    int NP, NG;
    scanf("%d%d", &NP, &NG);
    int i;
    for(i = 0; i < NP; ++i)
    {
        scanf("%d", &mouse[i].weight);
    }
    int tmp;
    for(i = 0; i < NP; ++i)
    {
        scanf("%d", &tmp);
        que.push(tmp);
    }
    int num;
    int forrank = 0;
    int index, max;
    int front;
    while(!que.empty())
    {
        num = que.size();
        for (i = 0; i < num; ++i)
        {
            front = que.front();
            mouse[front].rank = forrank;
            if(i % NG == 0)
            {//一组开始，或结束
                max = mouse[front].weight;
                //一组比赛完毕，记录结果
                if(i != 0)
                    que.push(index);
                index = front;
            }
            else if(mouse[front].weight >max)
            {//找出一组中最重的老鼠
                max = mouse[front].weight;
                index = front;
            }
            if(i == num - 1)
            { //最后一组中的最后一个元素，特殊处理
                que.push(index);
            }
            que.pop();
        }
        forrank += 1;//一轮结束
        if(num == 1)
            break;
    }
    for(i = 0; i < NP; ++i)
    {//计数排序
        count[mouse[i].rank] += 1;
    }
    for(i = forrank; i > 0; --i)
    {
        count[i - 1] += count[i];
    }
    for(i = 0; i < NP; ++i)
    {
        printf("%d", count[mouse[i].rank + 1] + 1);
        //printf("%d", count[forrank - mouse[i].rank] + 1);
        if(i < NP -1)
            putchar(' ');
    }
    putchar('\n');
    return 0;
}